package com.study.d4_io;

import java.io.FileInputStream;
import java.io.InputStream;

public class FileInputStreamDemo2 {
    public static void main(String[] args) throws Exception {
        //掌握文件字节输入流每次读取多个字节
        //1、创建一个文件字节输入流管道与源文件接通
       InputStream is = new FileInputStream("day10/src/dlei2.txt");
 /*         byte[] buffer = new byte[3];
       int read = is.read(buffer);
        System.out.println("内容："+new String(buffer));
        System.out.println("字节数："+read);
        int read2 = is.read(buffer);
        //读取多少就倒多少
        System.out.println("内容："+new String(buffer,0,2));
        System.out.println("字节数："+read2);
        int read3 = is.read(buffer);
        System.out.println(read3);*/

        //使用循环改进
        byte[] buffer = new byte[3];
        int len;
        while((len=is.read(buffer))!=-1){
            String arr = new String(buffer,0,len);
            System.out.print(arr);
        }

        //拓展：性能比较好，但是，无法避免读取汉字输出乱码的问题
        is.close();
    }
}
